package com.css.fxfzcpxx.modules.customizedServices.controller;


import com.alibaba.fastjson.JSONObject;
import com.css.fxfzcpxx.base.response.RestResponse;
import com.css.fxfzcpxx.modules.customizedServices.CurSevicesVo;
import com.css.fxfzcpxx.modules.customizedServices.entity.CusServices;
import com.css.fxfzcpxx.modules.customizedServices.service.CusServicesService;
import com.css.fxfzcpxx.modules.customizedServices.service.impl.CusServicesServiceImpl;
import com.css.fxfzcpxx.modules.thematicMap.entity.ThematicMap;
import com.css.fxfzcpxx.modules.thematicMap.param.QueParams;
import com.css.fxfzcpxx.modules.thematicMap.service.TheMapService;
import com.css.fxfzcpxx.modules.thematicMap.vo.ListVo;
import com.css.fxfzcpxx.modules.thematicMap.vo.ThematicMapVo;
import com.css.fxfzcpxx.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author 徐治宇
 * @program
 * @description 定制服务
 * @create 2022/8/8 10:39
 **/
@RestController
@RequestMapping("/cusServices")
@Slf4j
public class CusServicesController {
    @Resource
    CusServicesService cusServicesService;

    /***
     * 分页查询
     * @param curSevicesVo
     * @return
     */
    @GetMapping("/page")
    public RestResponse getPage(CurSevicesVo curSevicesVo, HttpServletRequest request){
        RestResponse response = null;
        try{
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize=Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            Map<String,Object> page=cusServicesService.getPage(curSevicesVo.getKeyword(),curPage,pageSize);
            response = RestResponse.succeed(page);
        }catch (Exception e){
            String errorMessage = "查询失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }
    /**
     * 保存
     *
     * @param cusServices
     * @return
     */
    @PostMapping("/save")
    public RestResponse save(@RequestBody CusServices cusServices) {
        RestResponse response = null;
        JSONObject jsonObject = new JSONObject();
        try {
            cusServicesService.save(cusServices);
            jsonObject.put("message", "保存成功");
            response = RestResponse.succeed(jsonObject);
        } catch (Exception e) {
            String errorMessage = "保存失败!";
            log.error(errorMessage,e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    /**
     * 查看
     *
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public RestResponse findById(@RequestParam("id") String id) {
        RestResponse response = null;
        try {
            CusServices infAchievement=cusServicesService.findById(id);
            response = RestResponse.succeed(infAchievement);
        } catch (Exception e) {
            String errorMessage = "查看失败!";
            log.error(errorMessage, e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

    /**
     * 修改查看状态
     *
     * @param curSevicesVo
     * @return
     */
    @PostMapping("/updateMessageStatus")
    public RestResponse updateMessageStatus(@RequestBody CurSevicesVo curSevicesVo) {
        RestResponse response = null;
        try {
            cusServicesService.updateMessageStatus(curSevicesVo);
        } catch (Exception e) {
            String errorMessage = "修改失败!";
            log.error(errorMessage, e);
            response = RestResponse.fail(errorMessage);
        }
        return response;
    }

}
